package com.sky.service.user.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.context.BaseContext;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.mapper.user.OrderDetailMapper;
import com.sky.mapper.user.UserPayOrdersMapper;
import com.sky.pojo.OrderDetail;
import com.sky.result.PageResult;
import com.sky.service.user.UserPayOrdersService;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.Size;
import java.util.List;

@Slf4j
@Service
public class UserPayOrdersServiceImpl implements UserPayOrdersService {
    @Autowired
    private UserPayOrdersMapper userPayOrdersMapper;
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    /**
     * 查询订单支付状态
     * @param page
     * @param pageSize
     * @param payStatus
     * @return
     */
    @Override
    public PageResult queryOrdersCheckStatus(Integer page, Integer pageSize, Integer payStatus) {
        PageHelper.startPage(page,pageSize);
        OrdersPageQueryDTO pageQueryDTO = new OrdersPageQueryDTO();
        pageQueryDTO.setUserId(BaseContext.getCurrentId());
        pageQueryDTO.setPage(page);
        pageQueryDTO.setPageSize(pageSize);
        pageQueryDTO.setPayStatus(payStatus);
        Page<OrderVO> pageResult=userPayOrdersMapper.queryOrdersCheckStatus(pageQueryDTO);
        for (OrderVO orderVO : pageResult) {
            List<OrderDetail> orderDetails =orderDetailMapper.selectByOrderId(orderVO.getId());
            orderVO.setOrderDetailList(orderDetails);
        }
        return new PageResult(pageResult.getTotal(),pageResult.getResult());
    }
}
